interface Square{
    color:string
    area:number
}

interface SquareConfig{//可选属性
    color?:string
    width?:number
}

function createSquare(config:SquareConfig):Square{
    let newSquare = {color:'white',area:100}
    if(config.color){
        newSquare.color = config.color
    }
    if(config.width){
        newSquare.area=config.width*config.width
    }
    return newSquare
}

let mySqquare=createSquare({color:'black'})
console.log(mySqquare)//{ color: 'black', area: 100 }
/** 
 * 只读属性
*/
interface Point {
    readonly x:number
    readonly y:number
}
let p1:Point ={x:10,y:20}
// P1.x=5;
let aa:number[]=[1,2,3,4]
let ro:ReadonlyArray<number> = aa
aa = ro as number[]